<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px">通道：</label>
                            <select name="channelId">
                                <option selected=""></option>
                                <option th:each="sysChannel : ${sysChannels}" th:text="${sysChannel.channelName}" th:value="${sysChannel.channelId}"></option>
                            </select>
                        </li>
                        <li th:if="${user.userType!=1}">
                            <label style="width: 80px">商户号：</label>
                            <input type="text" name="userCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">状态：</label>
                            <select name="status" th:with="type=${@dict.getType('sys_order_status')}">
                                <option selected=""></option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px">平台订单号：</label>
                            <input type="text" name="orderCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">下游订单号：</label>
                            <input type="text" name="orderChildCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">渠道流水号：</label>
                            <input type="text" name="orderChannelCode"/>
                        </li>
                        <li class="select-time">
                            <label style="width: 80px">创建时间：</label>
                            <input type="text" class="time-input" id="beginDate" placeholder="开始时间" name="beginDate"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endDate" placeholder="结束时间" name="endDate"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search();showStatistics()"><i class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 search-collapse">
            <div style="margin-top: 10px">
                <span type="text" class="btn btn-outline btn-info" id="todayOrderAmount">今日成功总额</span>
                <span th:if="${user.userType!=1}" type="text" class="btn btn-outline btn-info" id="todayAgentCommission">今日代理收益</span>
            </div>
            <br>
            <div style="margin-top: 3px">
                <span type="text" class="btn btn-outline btn-warning" id="monthOrderAmount">本月成功总额</span>
                <span th:if="${user.userType!=1}" type="text" class="btn btn-outline btn-warning" id="monthAgentCommission">本月代理收益</span>
            </div>
            <br>
            <div style="margin-top: 3px">
                <span type="text" class="btn btn-outline btn-danger" id="allOrderAmount">成功交易总额</span>
                <span type="text" class="btn btn-outline btn-danger" id="allOrderSize">成功订单数</span>
                <span type="text" class="btn btn-outline btn-danger" id="allMerAmount">商户收入总金额</span>
            </div>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:order:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a style="color: red">  tips:</a>导出功能请在非高峰期时候使用。(如发现在高峰期使用导出功能，将禁止此商户导出功能)
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:order:remove')}]];
    var prefix = ctx + "system/order";

    $(function() {
        showStatistics();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '商户订单id',
                    visible: false,
                    formatter: function(value, row, index) {
                        return '<input name="orderId" value='+value+' hidden="hidden">';
                    }
                },
                {
                    field: 'channelName',
                    title: '通道名称'
                },
                {
                    field: 'ip',
                    title: '访问ip'
                },
                {
                    field: 'orderCode',
                    title: '平台订单号'
                },
                {
                    field: 'orderChildCode',
                    title: '下游订单号'
                },
                {
                    field: 'orderChannelCode',
                    title: '通道订单号'
                },
                {
                    field: 'userCode',
                    title: '商户编号'
                },
                {
                    field: 'orderAmount',
                    title: '交易金额'
                },
                {
                    field: 'orderCharge',
                    title: '手续费'
                },
                {
                    field: 'orderLastAmount',
                    title: '实际金额'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value==0){
                            return "未处理";
                        }else {
                            return '<a style="color: green">处理完成</a>';
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '提交时间'
                },
                {
                    field: 'orderRemark',
                    title: '备注'
                },
                {
                    field: 'payMobile',
                    title: '付款人手机号'
                },
                {
                    field: 'payName',
                    title: '付款人名称'
                },
                {
                    field: 'payEmail',
                    title: '付款人邮箱'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.orderId + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });
    function showStatistics(){
        $.ajax({
            type: "POST",
            url: prefix + '/showStatistics' ,
            data: $("#formId").serialize() ,
            async: false,
            success: function (data) {
                $("#todayOrderAmount").html("今日成功总额: "+data.todayOrderAmount);
                $("#monthOrderAmount").html("本月成功总额: "+data.monthOrderAmount);
                $("#allOrderAmount").html("成功交易总额: "+data.allOrderAmount);
                $("#allOrderSize").html("成功订单数: "+data.allOrderSize);
                $("#todayAgentCommission").html("今日代理收益: "+data.todayAgentCommission);
                $("#monthAgentCommission").html("本月代理收益: "+data.monthAgentCommission);
                $("#allAgentCommission").html("今日成功总额: "+data.allAgentCommission);
                $("#allMerAmount").html("商户收入总金额: "+data.allMerAmount);
            },
            error: function () {
                $.modal.msgError("未知错误,请联系管理员:统计");
            }
        })
    }
</script>
</body>
</html>